<?php
         $cvename = $_GET['cve'];
         if($cvename == null || $cvename==''){
			echo 'No CVE has been spacified.';
		 }else{
?>

<html>

<head>
	
	<script type="text/javascript" src="jquery.js"></script>
	
	<style type="text/css"> 
		#cveinfo{
			margin:5px;
			padding:5px;
			background:#e5eecc;
			border:solid 2px #c3c3c3;
		}
                
       #cvelinks{
            margin:5px;
			padding:5px;
			background:#F5F5DC;
			border:solid 2px #c3c3c3;
        }	
	   table,td,th{
			margin:5px;
			padding:5px;
			border:solid 2px #191970; 
			border-collapse:collapse;
			background-color:#F8F8FF;
	   }
	   table{
			width:99%;
	   }
	   th{
			width:50%;
			text-align:left;
			background-color: #c3c3c3;
	   }
	   td{
			width:50%
	   }
	</style>

</head>

<body>
	
	<?php
            global $global_ws_address;
			$context = stream_context_create(array(
				'http' => array(
					'timeout' => 10      // Timeout in seconds
				)
			));

			$url1 = $global_ws_address.'o=allinfo&p1='.$cvename;
			$result1 = @file_get_contents($url1,0,$context);
			$result1 = json_decode($result1, true);
			if(!is_array($result1)){
				echo 'No results.';
			}else{
	?>
	<br/>
	<h2><?php echo $result1['cvename']?> INFORMATION</h2>

	<div id="cveinfo">
		<b>Description</b><br/>
		<p style="text-align:justify"><?php echo $result1['description']?></p>
		<b>Published | Year: </b><?php echo $result1['published'].' | '.$result1['year']?><br/>
		<b>Severity: </b><?php echo $result1['severity']?><br/>
		<b>CVSS score: </b><?php echo $result1['CVSS'].' (Exploit Score -'.$result1['cvss_exp'].' | Impact Score -'.$result1['cvss_imp'].')'?><br/>
		<br/>
		<b>Affected Product</b>
		<table>
			<tr>
				<th style="text-align:center;width:30%">Vendor Name</th>
				<th style="text-align:center;width:30%">Product Name</th>
				<th style="text-align:center;width:30%">Versions</th>
			</tr>
			<?php
				$limit = count($result1['vendor']);		
				for($i=0;$i<$limit;$i++){
					echo '<tr>';
						echo '<td style="width:30%">'.$result1['vendor'][$i].'</td>';
						echo '<td style="width:30%">'.$result1['product'][$i].'</td>';
						$splitArray = split(';',$result1['versions'][$i]);
						echo '<td style="width:30%">';
							foreach($splitArray as $value){
								echo $value;
								echo '<br/>';
							}
						echo '</td>';
					echo '</tr>';
				}
			?>
		</table>
		<br/>
		<b>Total Summary </b>(last updated: <?php echo $result1['last_update']?>)<br/>
		<table>
			<tr>
				<th>Search Result</th>
				<td><?php echo $result1['result']?> pages, used <?php echo $result1['crawl']?> pages</td>
			<tr>
			<tr>
				<th>Total Score</th>
				<td><?php echo $result1['total']?></td>
			<tr>
			<tr>
				<th>Component Score<th>
			<tr>
			<tr>
				<th>Basic Information Score</th>
				<td>
					<?php 
							echo $result1['basic'];
					?>
				</td>
			<tr>
			<tr>
				<th>Technical Information Score</th>
				<td>
					<?php 
							echo $result1['technical'];
					?>
				</td>
			<tr>
			<tr>
				<th>Exploit Information Score</th>
				<td>
					<?php 
							echo $result1['exploit'];
					?>
				</td>
			<tr>
			<tr>
				<th>Publicity Information Score</th>
				<td>
					<?php 
							echo $result1['publicity'];
					?>
				</td>
			<tr>
			<tr>
				<th>Remediation Information Score</th>
				<td>
					<?php 
							echo $result1['remediation'];
					?>
				</td>
			<tr>
		</table>	
	</div>

	<div id="cvelinks">
		<b>Result pages used. Click to see details.</b><br/>
		<?php
				$url2 = $global_ws_address.'o=pageinfo&p1='.$cvename.'&p2=';
				$result2 = @file_get_contents($url2,0,$context);
				$result2 = json_decode($result2, true);	
				if(!is_array($result2)){
					echo 'No results.';
				}else{
					echo '<ul>';
					foreach($result2 as $value){
						echo '<li style="background-color:#F8F8FF">';
						//for null titles
						if(!$value['title']) $value['title'] = 'Webpage'.$value[rank];
						echo '<a href="?q=node/15&cve='.$value[cvename].'&link='.$value[rank].'">'.$value['title'].'</a>';
						echo '</li>';
					}
					echo '</ul>';
				}
		?>
	</div>

	<a href="javascript:history.go(-1)"><< BACK TO PREVIOUS PAGE</a>

</body>

</html>
<?php
			}
		 }	
?>